/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package controler;

import graph.Node;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import view.NodePanel;

/**
 *
 * @author swider
 */
public class NodePanelControler {
    private NodePanel panel;
    private Controler controler;
    private NodeItemControler itemcontroler;
   

    public NodePanelControler(){
        panel = new NodePanel();
        initActions();
    }

    public NodePanelControler(Controler c){
        controler = c;
        panel = new NodePanel();
        initActions();
    }

    public NodePanel getView(){
        return panel;
    }

    public NodeItemControler getItemControler(){
        return itemcontroler;
    }
    public void initActions(){
        panel.addSave(new Save());
        panel.addSaveStateFocusListener(new SaveStateFocusLost());
        panel.addDelete(new Delete());
    }

    
     private void saveNode() {
            controler.saveNodeName(panel.getNodeName(),this);
            controler.saveNodeLock(panel.getLock(),this);
        }

    public void setNodeControler(NodeItemControler nodeItem){
        Node node = nodeItem.getModel();
        panel.setNodeName(node.getName());
        panel.setNodeLock(node.isLock());
        itemcontroler=nodeItem;
    }

    public void saveNodeState(){
        saveNode();
    }

    ////////////////////ActionListenery

    private class SaveStateFocusLost implements FocusListener{

        public void focusGained(FocusEvent e) {
        }

        public void focusLost(FocusEvent e) {
            System.out.println("Focus Lost");
            saveNode();
        }

    }
    
    private class Behavior implements ActionListener{

        public void actionPerformed(ActionEvent e) {
            System.out.println("Przycisk Zachowanie w Node");
        }
    }

    private class Save implements ActionListener{

         public void actionPerformed(ActionEvent e) {
            saveNode();
        }

       
    }

    private class Delete implements ActionListener{

         public void actionPerformed(ActionEvent e) {
            controler.deleteNode();
        }       
    }

   
}
